package br.com.NoTraffic.acceptance;

import br.com.NoTraffic.connector.UrlConnector;
import br.com.NoTraffic.decoder.Decoder;

public class StringBuilder {

	public static String[] zone1 = {
			"Holland Tunnel btwn Marin Blvd and Varick Street",
			"West Side Hwy btwn South Street and W 57th Street",
			"West Shore Expy btwn Staten Island Expy and Korean War Veterans Expy" };
	public static String[] zone2 = {
			"Lincoln Tunnel btwn JFK and Willow Ave and Dyer Ave",
			"I-95 George Washington Bridge btwn Riverside Drive and Hudson Terrace",
			"Manhattan Bridge btwn Bowery and Concord Street" };
	public static String[] zone3 = {
			"Long Island Expy btwn Queens Midtown Tunnel and Hwy 25 and 58",
			"Queens Midtown Tunnel btwn Long Island Expy and 2nd Ave",
			"Brooklyn Bridge btwn Park Row and Centre Street and Brooklyn Bridge Blvd" };
	public static String[] zone4 = {
			"Cross Bronx Expy btwn Riverside Drive and Throgs Neck Expy",
			"Harlem River Dr btwn US Hwy 1: Cross Bronx Expy and Triborough Bridge",
			"Major Deegan Expy btwn Bruckner Blvd and McLean Ave" };
	public static String URL = "http://www.nbcnewyork.com/traffic/";

	public static String getMessageFromZone(char zone) {
		Decoder decoder;
		String[] actualZone = zone1;
		
		if (zone == '1')
			actualZone = zone1;
		if (zone == '2')
			actualZone = zone2;
		if (zone == '3')
			actualZone = zone3;
		if (zone == '4')
			actualZone = zone4;
		else{
			
		}

		try {
			String HTML = UrlConnector.doHttpUrlConnection(URL);
			if (HTML == null) {
				return null;
			}

			decoder = new Decoder(HTML);

			String messageString = 
				    zone+ decoder.getAllInf(actualZone[0])+ '%' + shortName(actualZone[0])+ '$'
						+ decoder.getAllInf(actualZone[1])+ '%' + shortName(actualZone[1])+ '$'
					 	+ decoder.getAllInf(actualZone[2])+ '%' + shortName(actualZone[2])+ "$ç";
					
			return messageString;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} 	
	}
	
	private static String shortName(String longName){
		return Decoder.shortTerm(longName);
	}
}
